package com.hskn.hss.module.worklog.dto;

import com.hskn.hss.module.depart.entity.SysDepart;
import com.hskn.hss.module.tlcar.entity.TlCar;
import com.hskn.hss.module.tlcartype.entity.TlCarType;
import com.hskn.hss.module.tlemployee.entity.TlEmployee;
import com.hskn.hss.module.tlfacilities.entity.TlFacilities;
import com.hskn.hss.module.tlfacilitietype.entity.TlFacilitiesType;
import com.hskn.hss.module.tlopetation.entity.TlOperation;
import com.hskn.hss.module.tlworktype.entity.TlWorkType;
import lombok.Data;

import java.util.Map;

/**
 * 负责（车辆、人员、设施，等）
 */
@Data
public class InChargeSubjectDTO {
    /**
     * 主体id
     */
    private String subjectId;
    /**
     * 主体名称
     */
    private String subjectName;
    /**
     * 类型 (1:车辆，2：人员 ，3：设施（收集站、收集点、处理站、商圈社区、压缩箱、公测、停车场、中转站），
     * 4:园林 ，5：古树)
     */
    private Integer type;
    /**
     * 主体类型id
     */
    private String subjectTypeId;
    /**
     * 主体类型名称
     */
    private String subjectTypeName;
    /**
     * 主体作业id
     */
    private String subjectWorkTypeId;
    /**
     * 主体作业名称
     */
    private String subjectWorkTypeName;
    /**
     * 主体机构id
     */
    private String subjectDepId;
    /**
     * 主体机构名称
     */
    private String subjectDepName;

    public static InChargeSubjectDTO buildInChargeSubjectDTO(TlCar car, Map<String, TlCarType> carTypeMap,
                                                             Map<String, TlOperation> operationMap, Map<String, SysDepart> departMap) {
        InChargeSubjectDTO inChargeSubjectDTO = new InChargeSubjectDTO();
        inChargeSubjectDTO.setSubjectId(car.getId());
        inChargeSubjectDTO.setType(1);
        inChargeSubjectDTO.setSubjectName(car.getCarnumber());
        inChargeSubjectDTO.setSubjectTypeId(car.getCartypeid());
        if (carTypeMap.containsKey(car.getCartypeid())) {
            inChargeSubjectDTO.setSubjectTypeName(carTypeMap.get(car.getCartypeid()).getTypename());
        }
        inChargeSubjectDTO.setSubjectWorkTypeId(car.getCarcategory());
        if (operationMap.containsKey(car.getCarcategory())) {
            inChargeSubjectDTO.setSubjectWorkTypeName(operationMap.get(car.getCarcategory()).getOperationtype());
        }
        inChargeSubjectDTO.setSubjectDepId(car.getCardeptid());
        if (departMap.containsKey(car.getCardeptid())) {
            inChargeSubjectDTO.setSubjectDepName(departMap.get(car.getCardeptid()).getDepartName());
        }
        return inChargeSubjectDTO;
    }

    public static InChargeSubjectDTO buildInChargeSubjectDTO(TlEmployee employee, Map<String, TlWorkType> workTypeMap, Map<String, SysDepart> departMap) {
        InChargeSubjectDTO inChargeSubjectDTO = new InChargeSubjectDTO();
        inChargeSubjectDTO.setSubjectId(employee.getId());
        inChargeSubjectDTO.setType(2);
        inChargeSubjectDTO.setSubjectName(employee.getName());
        inChargeSubjectDTO.setSubjectTypeId(employee.getWorktype());
        if (workTypeMap.containsKey(employee.getWorktype())) {
            inChargeSubjectDTO.setSubjectTypeName(workTypeMap.get(employee.getWorktype()).getWorktype());
        }
//        inChargeSubjectDTO.setSubjectWorkTypeId(employee.getPersontype());
        inChargeSubjectDTO.setSubjectWorkTypeName(employee.getPersontype());
        inChargeSubjectDTO.setSubjectDepId(employee.getDeptid());
        if (departMap.containsKey(employee.getDeptid())) {
            inChargeSubjectDTO.setSubjectDepName(departMap.get(employee.getDeptid()).getDepartName());
        }
        return inChargeSubjectDTO;
    }
    public static InChargeSubjectDTO buildInChargeSubjectDTO(TlFacilities facilities ,Integer type, Map<String, TlFacilitiesType> facilitiesTypeMap, Map<String, SysDepart> departMap) {
        InChargeSubjectDTO inChargeSubjectDTO = new InChargeSubjectDTO();
        inChargeSubjectDTO.setSubjectId(facilities.getId());
        inChargeSubjectDTO.setType(type);
        inChargeSubjectDTO.setSubjectName(facilities.getFaclname());
        inChargeSubjectDTO.setSubjectTypeId(facilities.getFacltypeid());
        if (facilitiesTypeMap.containsKey(facilities.getFacltypeid())) {
            inChargeSubjectDTO.setSubjectTypeName(facilitiesTypeMap.get(facilities.getFacltypeid()).getFacilitietypename());
        }
        inChargeSubjectDTO.setSubjectDepId(facilities.getDeptid());
        if (departMap.containsKey(facilities.getDeptid())) {
            inChargeSubjectDTO.setSubjectDepName(departMap.get(facilities.getDeptid()).getDepartName());
        }
        return inChargeSubjectDTO;
    }

}
